//用于管理组件内部的动画播放
const RESSTATE = require("../states/resstates");
const tools = require("../pub/tools");

class ElemAnimate{
    constructor( elem ){
        this._elem = elem;
    }

    do( meth ){
        let args = Array.prototype.slice.call(arguments);
        let newArgs = args.splice(1);
        let me = this;
        if( newArgs[newArgs.length-1] instanceof cc.AudioClip ){
            tools.playEffect(newArgs[newArgs.length-1]);
            newArgs.splice(newArgs.length-1);
        }
        let p = new Promise( (resolve, reject)=>{
            let arr= [resolve , reject];
            if( typeof meth == 'function'){
                meth.apply( args.splice(1,1) , arr.concat(args.splice(2)) )
            }else if( me[meth] ){
                me[meth].apply( this , arr.concat(newArgs) )
            }else{
                resolve( RESSTATE.NOTHING );
                reject('cant find meth:' + meth);
            }
        });
        return p;
    }
}
module.exports = ElemAnimate; 